package com.itheima.array;

import java.util.Scanner;

public class BianLi {
    public static void main(String[] args) {
        int[] arr = {1, 90, 78, 65, 45, 67, 88, 99, 34};

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]);
        }

        //获取数组最大值
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
        }
        System.out.println("最大值" + max);

        //获取数组最小值
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        System.out.println("最小值" + min);

        //求和
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        System.out.println("求和等于"+sum);

        //寻找输入的数
        Scanner sc = new Scanner(System.in);
        System.out.println("输入需要查找的数字:");
        int x = sc.nextInt();
        int i = 0;
        while( x != arr[i]){
            i++;
            if(i == arr.length){
                System.out.println("没有在数组中找到数字,请重新输入:");
                i = 0;
                x = sc.nextInt();
            }
        }
        if (i < arr.length){
            System.out.println("数字在第"+i+"位");
        }
    }
}
